// 任务调度器
let taskId = 1
function workLoop(deadline) {
    // 检测浏览器的空闲时间
    // console.log(deadline.timeRemaining());

    taskId++

    let shouldYield = false
    while (!shouldYield) {
        console.log(`taskId:${taskId} run task`);
        shouldYield = deadline.timeRemaining() < 1;
    }
    requestIdleCallback(workLoop)
}

requestIdleCallback(workLoop)